{template 'public/header'}
{template 'plateform/nav'}
{template 'plateform/trade-nav'}
<style type="text/css">
	.order-detail-info>div{margin-bottom:10px; padding-left:15px;}
	.page-trade-order h4{font-size:14px; font-weight:700;}
	.page-trade-order .form-group{margin-bottom:0;}
	.page-trade-order .form-group .control-label{font-weight:normal; color:#999;}
	.page-trade-order .order-infos{border-right:1px solid #ddd;}
	.page-trade-order .parting-line{height:1px;border-top:1px dashed #e5e5e5; margin:3px 0;}
	.page-trade-order .order-state{padding-left:40px; position:relative; margin:20px 0 40px;}
	.page-trade-order .order-state>span{color:#07d; position:absolute; left:0; top:5px; font-size:25px; display:inline-block; width:30px; height:30px; border:1px solid #07d; border-radius:30px; text-align:center; line-height:30px;}
	#close-order ul li{padding:5px 15px; cursor:pointer;}
	#close-order ul li:hover{background:#eee;}
	.fix a.js-order-edit-address{display:none; color:red;}
	.fix:hover a.js-order-edit-address{display:inline;}
	.page-trade-order .col-sm-9{word-break: break-word; overflow:hidden;}
	.table-log>tbody>tr>td{border-top:none;}
</style>
{if $op == 'list'}
<div class="main">
	<div class="panel panel-info">
		<div class="panel-heading">筛选</div>
		<div class="panel-body">
			<form action="./index.php" method="get" class="form-horizontal" role="form">
				<input type="hidden" name="c" value="site">
				<input type="hidden" name="a" value="entry">
				<input type="hidden" name="m" value="we7_wmall">
				<input type="hidden" name="do" value="ptforder"/>
				<input type="hidden" name="op" value="list"/>
				<input type="hidden" name="status" value="{$_GPC['status']}"/>
				<input type="hidden" name="is_pay" value="{$_GPC['is_pay']}"/>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">支付状态</label>
					<div class="col-sm-9 col-xs-9 col-md-9">
						<div class="btn-group">
							<a href="{php echo filter_url('is_pay:-1');}" class="btn {if $is_pay == -1}btn-primary{else}btn-default{/if}">不限</a>
							<a href="{php echo filter_url('is_pay:0');}" class="btn {if $is_pay == 0}btn-primary{else}btn-default{/if}">未支付</a>
							<a href="{php echo filter_url('is_pay:1');}" class="btn {if $is_pay == 1}btn-primary{else}btn-default{/if}">已支付</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">所属门店</label>
					<div class="col-sm-6 col-xs-6 col-md-2">
						<select name="sid" class="form-control">
							<option value="0" {if $sid == 0}select{/if}>不限</option>
							{loop $stores $store}
								<option value="{$store['id']}" {if $sid == $store['id']}select{/if}>{$store['title']}</option>
							{/loop}
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">订单编号</label>
					<div class="col-sm-6 col-xs-6 col-md-2">
						<input class="form-control" name="ordersn" placeholder="输入订单编号" type="text" value="{$_GPC['ordersn']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">用户信息</label>
					<div class="col-sm-6 col-xs-6 col-md-2">
						<input class="form-control" name="keyword" placeholder="输入用户名或手机号" type="text" value="{$_GPC['keyword']}">
					</div>
				</div>
				<div class="form-group clearfix">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">下单时间</label>
					<div class="col-sm-6 col-xs-6 col-md-2">
						{php echo tpl_form_field_daterange('addtime', array('start' => date('Y-m-d', $starttime), 'end' => date('Y-m-d', $endtime)));}
					</div>
					<div class="col-xs-12 col-sm-6 col-md-6">
						<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
						<a class="btn btn-success btn-export" href="javascript:;"><i class="fa fa-download"></i> 导出订单</a>
					</div>
				</div>
			</form>
		</div>
	</div>
	{if $wait_total > 0}
	<div class="alert alert-danger">
		<i class="fa fa-bell"></i> {$wait_total}个订单未处理, 请尽快处理.
	</div>
	{/if}
	<form class="form-horizontal" action="{php echo $this->createWebUrl('order', array('op' => 'status'));}" id="form-order" method="post">
		<ul class="order-nav order-nav-tabs">
			<li {if $status == 0}class="active"{/if}><a href="{php echo filter_url('status:0');}">所有订单</a></li>
			<li {if $status == 1}class="active"{/if}><a href="{php echo filter_url('status:1');}">未处理订单</a></li>
			<li {if $status == 2}class="active"{/if}><a href="{php echo filter_url('status:2');}">已确认订单</a></li>
			<li {if $status == 3}class="active"{/if}><a href="{php echo filter_url('status:3');}">待配送订单</a></li>
			<li {if $status == 4}class="active"{/if}><a href="{php echo filter_url('status:4');}">配送中订单</a></li>
			<li {if $status == 5}class="active"{/if}><a href="{php echo filter_url('status:5');}">已完成订单</a></li>
			<li {if $status == 6}class="active"{/if}><a href="{php echo filter_url('status:6');}">已取消订单</a></li>
		</ul>
		<div class="panel panel-default">
			<div class="panel-body table-responsive" style="overflow:inherit">
				<table class="table table-hover">
					<thead class="navbar-inner">
						<tr>
							<th width="50">编号</th>
							<th>门店</th>
							<th>预定人/电话</th>
							<th>订单类型</th>
							<th>支付方式</th>
							<th>订单状态</th>
							<th>份数/总价</th>
							<th>优惠金额</th>
							<th>优惠后价格</th>
							<th>下单时间</th>
							<th style="width:250px; text-align:right;">详情</th>
						</tr>
					</thead>
					<tbody>
						{loop $data $dca}
						<tr>
							<td><b>{$dca['id']}</b></td>
							<td><b>{$stores[$dca['sid']]['title']}</b></td>
							<td>
								{$dca['username']}
								<br>
								{$dca['mobile']}
							</td>
							<td>
								<span class="{$order_types[$dca['order_type']]['css']}">{$order_types[$dca['order_type']]['text']}</span>
								<br>
								<span class="label label-info label-br">收货码:{$dca['code']}</span>
							</td>
							<td>
								{if !$dca['is_pay']}
									<span class="label label-danger">未支付</span>
								{else}
									<span class="{$pay_types[$dca['pay_type']]['css']}">{$pay_types[$dca['pay_type']]['text']}</span>
								{/if}
								<br>
								<span class="label label-info label-br dist hide" data-lat="{$dca['location_x']}"  data-lng="{$dca['location_y']}">距离:未知</span>
							</td>
							<td>
								<span class="{$order_status[$dca['status']]['css']}">
									{$order_status[$dca['status']]['text']}
								</span>
								{if $dca['is_refund'] == 1}
									<br>
									<span class="label label-danger label-br">有退款申请</span>
								{/if}
								{if $dca['deliveryer_id'] > 0}
									<br>
									<span class="label label-info label-br">配送员: {$deliveryers[$dca['deliveryer_id']]['title']}</span>
								{/if}
							</td>
							<td>
								{$dca['num']}份/{$dca['total_fee']}元
							</td>
							<td>{$dca['discount_fee']}元</td>
							<td><span class="label label-info">{$dca['final_fee']}元</span></td>
							<td>{php echo date('Y-m-d H:i', $dca['addtime'])}</td>
							<td class="text-right">
								<a href="{php echo $this->createWeburl('ptforder', array('op' => 'detail', 'id' => $dca['id']))}" class="btn btn-success btn-sm" title="查看详情" data-toggle="tooltip" data-placement="top">详情</a>
							</td>
						</tr>
						{/loop}
					</tbody>
				</table>
			</div>
		</div>
		{$pager}
	</form>
</div>
{elseif $op == 'detail'}
<form class="form-horizontal" role="form">
	<div class="page-trade-order">
		<div class="order-list">
			<div class="freight-content">
				<div class="freight-template-item panel panel-default">
					<div class="panel-body clearfix">
						<div class="col-xs-12 col-sm-6 order-infos">
							<h4>订单信息</h4>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">订单编号：</label>
								<div class="col-md-9 form-control-static">
									{$order['ordersn']}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">下单时间：</label>
								<div class="col-md-9 form-control-static">
									{php echo date('Y-m-d H:i', $order['addtime']);}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">订单状态：</label>
								<div class="col-md-9 form-control-static">
									<span class="{$order_status[$order['status']]['css']}">{$order_status[$order['status']]['text']}</span>
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">配送方式：</label>
								<div class="col-md-9 form-control-static">
									<span class="{$order_types[$order['order_type']]['css']}">{$order_types[$order['order_type']]['text']}</span>
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">配送/自提时间：</label>
								<div class="col-md-9 form-control-static">
									{$order['delivery_day']}~{$order['delivery_time']}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">付款方式：</label>
								<div class="col-md-9 form-control-static">
									{if !$order['is_pay']}
										<span class="label label-danger">未支付</span>
									{else}
										<span class="{$pay_types[$order['pay_type']]['css']}">{$pay_types[$order['pay_type']]['text']}</span>
									{/if}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">下单人信息：</label>
								<div class="col-md-9 form-control-static">
									{$order['username']} {$order['mobile']}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">配送地址：</label>
								<div class="col-md-9 form-control-static">
									{$order['address']}
								</div>
							</div>
							<div class="parting-line"></div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">备注：</label>
								<div class="col-md-9 form-control-static">
									{$order['note']}
								</div>
							</div>
						</div>

						<div class="col-xs-12 col-sm-6">
							<h4>订单费用</h4>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">商品价格：</label>
								<div class="col-md-9 form-control-static">
									￥ {$order['price']}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">包装费：</label>
								<div class="col-md-9 form-control-static">
									￥ {$order['pack_fee']}
								</div>
							</div>
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">配送费：</label>
								<div class="col-md-9 form-control-static">
									￥ {$order['delivery_fee']}
								</div>
							</div>
							{if $order['discount_fee'] > 0}
								{loop $discount $row}
									<div class="form-group clearfix">
										<label class="col-md-3 control-label">{$row['note']}：</label>
										<div class="col-md-9 form-control-static">
											- ￥ {$row['fee']}
										</div>
									</div>
								{/loop}
							{/if}
							<div class="form-group clearfix">
								<label class="col-md-3 control-label">合计：</label>
								<div class="col-md-9 form-control-static">
									￥ {$order['final_fee']}
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="panel panel-default">
		<div class="panel-heading">商品信息【共 <strong>{$order['num']}</strong> 份,总价 <strong>{$order['price']}</strong> 元】</div>
		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>
						<th>商品</th>
						<th>份数</th>
						<th>小计(元)</th>
						<th></th>
					</tr>
					{if !empty($order['goods'])}
						{loop $order['goods'] $or}
							<tr>
								<td>{$or['goods_title']}</td>
								<td>{$or['goods_num']} 份</td>
								<td>{$or['goods_price']} 元</td>
								<td>
									<a class="btn btn-success" target="_blank" href="{php echo $this->createWeburl('goods', array('op' => 'post', 'id' => $or['goods_id']));}">商品信息</a>
								</td>
							</tr>
						{/loop}
					{/if}
				</thead>
			</table>
		</div>
	</div>
	{if $order['is_comment'] == 1}
		<div class="panel panel-default">
			<div class="panel-heading">订单评价</div>
			<div class="panel-body table-responsive">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">商品质量:</label>
					<div class="col-sm-9 col-xs-9 col-md-9">
						<p class="form-control-static">
							<?php
								for($i = 0; $i < $comment['goods_quality']; $i++) {
									echo '<i class="fa fa-star"></i>';
								}
								for($i = $comment['goods_quality']; $i < 5; $i++) {
									echo '<i class="fa fa-star-o"></i>';
								}
							?>
						</p>
					</div>	
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">配送服务:</label>
					<div class="col-sm-9 col-xs-9 col-md-9">
						<p class="form-control-static">
							<?php
								for($i = 0; $i < $comment['delivery_service']; $i++) {
									echo '<i class="fa fa-star"></i>';
								}
								for($i = $comment['delivery_service']; $i < 5; $i++) {
									echo '<i class="fa fa-star-o"></i>';
								}
							?>
						</p>
					</div>
				</div>
				{if !empty($comment['data']['good'])}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-1 control-label"><i class="fa fa-thumbs-o-up"></i> 点赞商品:</label>
						<div class="col-sm-9 col-xs-9 col-md-9">
							<p class="form-control-static">
								{loop $comment['data']['good'] $good}
									{$good} &nbsp;
								{/loop}
							</p>
						</div>	
					</div>
				{/if}
				{if !empty($comment['data']['bad'])}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-1 control-label"><i class="fa fa-thumbs-o-down"></i> 差评菜品:</label>
						<div class="col-sm-9 col-xs-9 col-md-9">
							<p class="form-control-static">
								{loop $comment['data']['bad'] $bad}
									{$bad} &nbsp;
								{/loop}
							</p>
						</div>	
					</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">评价:</label>
					<div class="col-sm-9 col-xs-9 col-md-9">
						<p class="form-control-static">{$comment['note']}</p>
					</div>
				</div>
				{if !empty($comment['thumbs'])}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-1 control-label">有图有真相:</label>
						<div class="col-sm-9 col-xs-9 col-md-11">
							{loop $comment['thumbs'] $thumb}
								<img src="{php echo tomedia($thumb);}" alt="" class="img-thumbnail" style="width: 200px;"/>
							{/loop}
						</div>
					</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-1 control-label">审核状态:</label>
					<div class="col-sm-9 col-xs-9 col-md-9">
						<p class="form-control-static">
							{if $comment['status'] == 1}
								<span class="label label-success">审核通过</span>
							{elseif !$comment['status']}
								<span class="label label-danger">审核未通过</span>
							{else}
								<span class="label label-default">审核中</span>
							{/if}
						</p>
					</div>
				</div>
			</div>
		</div>
	{/if}
	{if !empty($logs)}
		<div class="panel panel-default">
			<div class="panel-heading">订单日志</div>
			<div class="panel-body table-responsive">
				<table class="table table-hover table-log">
					{loop $logs $log}
					<tr>
						<td>
							<p><i class="fa fa-info-circle"></i> <strong>{php echo date('Y-m-d H:i', $log['addtime']);} {$log['title']}</strong></p> 
							<p style="padding-left:15px; ">{$log['note']}</p> 
						</td>
					</tr>
					{/loop}
				</table>
			</div>
		</div>
	{/if}
</form>
{/if}

<div class="modal fade" id="order-export" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog ">
		<form action="./index.php">
			<input type="hidden" name="c" value="site">
			<input type="hidden" name="a" value="entry">
			<input type="hidden" name="m" value="we7_wmall">
			<input type="hidden" name="do" value="ptforder"/>
			<input type="hidden" name="op" value="export"/>
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title">导出订单</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label>所属门店</label>
						<br>
						<select name="sid" class="form-control">
							<option value="0">所有门店</option>
							{loop $stores $store}
							<option value="{$store['id']}">{$store['title']}</option>
							{/loop}
						</select>
					</div>
					<div class="form-group">
						<label>订单编号</label>
						<br>
						<input class="form-control" name="ordersn" placeholder="输入订单编号" type="text" value="{$_GPC['ordersn']}">
					</div>
					<div class="form-group">
						<label>导出时间段</label>
						<br>
						{php echo tpl_form_field_daterange('addtime', array('start' => date('Y-m-d', $starttime), 'end' => date('Y-m-d', $endtime)));}
						<div class="help-block">只导出已完成的订单</div>
					</div>
					<div class="form-group">
						<label>附加会员字段</label>
						<br/>
						{loop $fields $key $field}
							<label class="checkbox-inline">
								<input type="checkbox" name="fields[]" value="{$key}"> {$field}
							</label>
						{/loop}
					</div>
				</div>
				<div class="modal-footer text-center">
					<input type="hidden" name="token" value="{$_W['token']}">
					<a class="btn btn-primary btn-export-submit" href="javascript:;">确定导出</a>
					<a class="btn btn-default" data-dismiss="modal" aria-label="Close">取消</a>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
$(function(){
	$('.btn-export').click(function(){
		$('#order-export').modal('show');
		$('.btn-export-submit').click(function(){
			$('#order-export form').submit();
		});
	});
});
</script>
{template 'common'}
{template 'public/footer'}
